package com.scott.configuration.springmvc;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 黄后林  如果mvc去扫描controller并且spring也扫描  事务不会回滚
 * @version 1.0
 * @date 2021-11-26 10:06:38
 */
@Configuration
@ComponentScan(value = "com.scott.oa",useDefaultFilters = false, includeFilters = {
        @ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class})
})
@EnableWebMvc
public class SpringMVCConfiguration implements WebMvcConfigurer {



    @Bean
    public CommonsMultipartResolver multipartResolver(){
        CommonsMultipartResolver resolver= new CommonsMultipartResolver();
        resolver.setMaxUploadSize(10240000);
        return resolver;
    }

    @Override
    public void addCorsMappings(CorsRegistry registry){
        registry.addMapping("/**")                           //路径
                .allowedOrigins("*")                                   //域名
                .allowedMethods("GET", "POST")                         //方法
                .allowedHeaders("*")                                   //请求投
                .allowCredentials(true)                                //证书
                .maxAge(3600*24);                                      //时间
    }
}
